﻿using System;
using Twitter;

namespace TemperatureBots
{
	public class CelsiusToFahrenheitGreeting : IGreeter
	{
		public void Greet(IBotClient botClient, string newFriend)
		{
			botClient.Messages.Send(newFriend, String.Format("Hello {0}, this is the friendliest C2F bot! Just send 'D C2F 35' and you'll get '95'", newFriend));
		}
	}

	public class CelsiusToFahrenheitMessageProcessor : IMessageProcessor
	{
        public RunNextProcessor Process(IBotClient botClient, Message message)
		{
			double c = Convert.ToDouble(message.Text);
			double f = (9d / 5d) * c + 32;

			botClient.Messages.Send(message.Sender.ScreenName, string.Format("{0} celsius is {1} fahrenheit!", c, f));

            return RunNextProcessor.Yes;
		}

		public bool CanProcess(Message message)
		{
			// Can only process the message if it contains a valid double value.
			double value;
			return double.TryParse(message.Text, out value);
		}
	}
}
